﻿using HP.HPTRIM.ServiceModel;
using System;

namespace DocuSignPlugin
{
    public class DocuSignLogoutService : BaseDocuSignService
    {
        public object Post(DocuSignLogout request)
        {
            try
            {
                LoginDetails loginDetails = this.TrimHelper.getUserCredentials(Request);

                if (loginDetails.IsLoggedIn())
                {
                    this.Docusign.Logout(loginDetails);

                    Response.Cookies.DeleteCookie("docusign.auth");
                }
                Response.AddHeader("Location", Request.UrlReferrer.ToString());
                Response.StatusCode = 303;
            }
            catch (Exception ex)
            {
                return new DSErrorResponse() { ResponseStatus = new ServiceStack.ServiceInterface.ServiceModel.ResponseStatus() { Message = ex.Message } };
            }
            return null;
        }
    }
}
